import React, {Component} from 'react';
import {Link} from 'react-router-dom';
// import axios from 'axios';
export default class UsetList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            users: []
        };
    }
    componentDidMount() {
        // let self = this; axios     .get('http://localhost:3000/json/data.json')
        // .then(function (res) {         let users = res.data.userList;
        // localStorage.setItem('users', users);         self.setState({users});     })
        //   .catch(function (err) {});
        let userStr = localStorage.getItem('users');
        let users = userStr
            ? JSON.parse(userStr)
            : [];
        this.setState({users});
    }
    render() {
        // let usersDom = this.state.users.map()
        return (
            <div className="list-group">
                {this
                    .state
                    .users
                    .map((user, index) => (
                        <Link key={index} to={"/user/detail/" + user.id}>
                            <button className="list-group-item">{user.name}</button>
                        </Link>
                    ))
}
                {/* <Link to="/user/detail/1"><button className="list-group-item">张三</button></Link>
<Link to="/user/detail/2"><button className="list-group-item">李四</button></Link>
<Link to="/user/detail/3"><button className="list-group-item">王五</button></Link> */}
            </div>
        )
    }
};